package com.itheima.wemedia.listener;

import com.heima.model.kafka.message.KafkaMessageConstants;
import com.itheima.wemedia.service.WmNewsAutoScanService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;

import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;

@Component
@Slf4j
public class NewsAutoScanListener {

    @Resource
    private WmNewsAutoScanService wmNewsAutoScanService;

    @KafkaListener(topics = KafkaMessageConstants.WM_NEWS_AUTO_SCAN_TOPIC,groupId = "WM_NEWS_AUTO_SCAN")
    public void wmNewsAutoScanListener(ConsumerRecord<String,String> record) throws InvocationTargetException, IllegalAccessException {
        String value = record.value();

        if (StringUtils.isNotBlank(value)) {
            log.info("接收到消息-->>>>>>>>文章ID:{}", value);
            wmNewsAutoScanService.autoScanNews(Long.parseLong(value));
            log.info("文章自动审核完成 , 文章ID:{}", value);
        }

    }

}
